package com.egdd.video.controller;

import com.egdd.video.common.api.ApiResult;
import com.egdd.video.pojo.Video;
import com.egdd.video.service.iml.VideoServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Api(tags = {"视频操作相关"})
@RequestMapping("/video")
@RestController
public class VideoController {
    @Autowired
    VideoServiceImpl videoService;

    @ApiOperation("通过视频合集id获取该id下面的所有视频信息")
    @GetMapping(value = "/getVideoByAlbumId")

    @ApiImplicitParams({
            @ApiImplicitParam(name = "albumId", value = "视频合集id", defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页码", defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页码大小", defaultValue = "10", paramType = "query"),
    })
    public ApiResult getVideoByAlbumId(int albumId, int page, int pageSize) {
        List<Video> data = videoService.getVideoByAlbumId(albumId, page, pageSize);
        if (data == null) {
            return ApiResult.success(Arrays.<Video>asList());
        } else {
            return ApiResult.success(data);
        }
    }


    @ApiOperation("根据主键删除一个视频信息")
    @GetMapping(value = "/delVideoById")
    @ApiImplicitParam(
            name = "id", value = "视频id", defaultValue = "255", paramType = "query"
    )
    public ApiResult delVideoById(int id) {
        int count = videoService.delVideoById(id);
        if (count == 1) {
            return ApiResult.success(count);
        } else {
            return ApiResult.error("视频删除失败");
        }
    }


    @ApiOperation("上传视频信息")
    @PostMapping(value = "/uploadVideo")
    public ApiResult uploadVideo(@RequestBody Video video) {
        int count = videoService.uploadVideo(video);
        if (count == 1) {
            return ApiResult.success(count);
        } else {
            return ApiResult.error("视频添加失败");
        }
    }


}
